import React from "react";
import {plusAction,minusAction} from "./redux/actions";
import {connect} from "react-redux";

class Counter extends React.Component{
  constructor(props){
    super(props);

  }

  render(){
    return(
      <div>
        <button onClick={()=>{
          this.props.plus();
        }}>+</button>
        <div>{this.props.count}</div>
        <button  onClick={()=>{
          this.props.minus()
        }}>-</button>
      </div>
    );
  }
}

function mapActionToProps(dispatch){
  return{
    plus:()=>{dispatch(plusAction())},
    minus:()=>{dispatch(minusAction())}
  }
}

function mapStateToProps(rootReducer){
  return{
    count:rootReducer.counterReducer.count
  }
}

export default connect(mapStateToProps,mapActionToProps)(Counter);


// function connect(mapStateToProps,mapActionToProps){
//   var state = mapStateToProps(rootReducer);
//   var action = mapActionToProps(dispatch);
//   return (component)=>{
//     component.props.state = state;
//     component.props.action = action;
//     return component;
//   }
// }